package com.hank.controller;

import com.hank.entity.dto.RegisterUser;
import com.hank.service.IUserService;
import com.hank.service.UserLoginService;
import com.hank.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hank
 * @since 2023-04-23
 */
@RestController
@RequestMapping("/user")
@Api(tags = "登录相关接口")
public class UserLoginController {

    @Resource
    UserLoginService loginService;

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public R userRegister(RegisterUser registerUser){
        return loginService.userRegister(registerUser);
    }

    @GetMapping("/exists")
    @ApiOperation("判断用户是否存在")
    public R userExists(@RequestParam(name = "username",required = true) String username){
        return loginService.uniqueUsername(username);

    }

    @GetMapping("/login")
    @ApiOperation("用户登录")
    public R userLogin(@RequestParam(name = "username",required = true) String username,
                       @RequestParam(name = "password",required = true) String password){
        return loginService.login(username,password);
    }

    @GetMapping("/logout")
    @ApiOperation("用户退出")
    public R userLogout(){
        return loginService.logout();
    }

}
